package controller;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.TreeMap;

public class WaitingMessageManager {

	private TreeMap <String, ArrayList <String>> waitingText;
	private TreeMap <String, ArrayList <InetAddress[]>> waitingReceivers ;
	
	public WaitingMessageManager () {
		/* Create waiting message TreeMap... */
		this.waitingText = new TreeMap <String, ArrayList <String>> () ;
		this.waitingReceivers = new TreeMap <String, ArrayList <InetAddress[]>> () ;
	}
	
	public void add (String identifier, String message, InetAddress[] receivers) {
		if (!this.waitingText.containsKey(identifier)) {
			this.waitingText.put(identifier, new ArrayList <String> ()) ;
			this.waitingReceivers.put(identifier, new ArrayList <InetAddress[]> ()) ;
		}
		this.waitingText.get(identifier).add(message) ;
		this.waitingReceivers.get(identifier).add(receivers) ;
	}

	public boolean contains (String identifier) {
		return this.waitingText.containsKey (identifier) ;
	}
	
	public ArrayList <String> getMessages (String identifier) {
		return this.waitingText.get(identifier) ;
	}
	
	public ArrayList <InetAddress[]> getReceivers (String identifier) {
		return this.waitingReceivers.get(identifier) ;
	}
	
	public void remove (String identifier) {
		this.waitingText.remove(identifier) ;
		this.waitingReceivers.remove(identifier) ;
	}
	
}
